package identical_scheduling_algorithm;

import java.util.ArrayList;

/**
 * 
 * Der ListScheduling Algorithmus für die verbleibenden kleinen Jobs aus Algorithmus 1 aus ...jansen.
 * 
 * 
 * @author Oliver Hense
 * @author Tim Dopke
 *
 */


public class ListSchedulingForSmallJobs {

	int numberOfJobs;
	int numberOfMachines;
	double[] machines;
	ArrayList<Double> jobs;
	double max;

	public ListSchedulingForSmallJobs(int numberOfMachines, ArrayList<Double> jobs,
			double[] machines) {
		this.jobs = jobs;
		this.numberOfMachines = numberOfMachines;
		this.numberOfJobs = jobs.size();
		this.machines = machines;
	}

	public double[] solve() {
		for (int i = 0; i < numberOfJobs; i++) {
			int pos = findMin(machines);
			machines[pos] = machines[pos] + jobs.get(i);
		}
		double max = 0.;
		for (int i = 0; i < numberOfMachines; i++)
			max = Math.max(max, machines[i]);
		this.max = max;
		return machines;
	}

	public double getMax() {
		return max;
	}

	public int findMin(double[] a) {
		double min = Integer.MAX_VALUE;
		int pos = 0;

		for (int i = 0; i < a.length; i++) {
			if (min > a[i]) {
				min = a[i];
				pos = i;
			}

		}
		return pos;

	}
}